package san.java.day14;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

/**
 * 通过Reflect获取类的方法:
 *
 */

public class Reflect_06 {

    public static void testGetMethodByReflect() throws Exception {
        Class<?> dogClass = Class.forName("san.java.day14.GoldenDog");

        // 1. 获取到类的所有公有方法
        Method[] methods = dogClass.getMethods();
        for (Method m: methods) {
            System.out.println("方法名: " + m.getName());
            System.out.println("返回值类型: " + m.getReturnType());
            System.out.println("修饰符: " + m.getModifiers());

            Class<?>[] parameterTypes = m.getParameterTypes();
            for (Class c: parameterTypes) {
                System.out.println("参数类型: " + c.getName());
            }

            System.out.println("==============================");
        }

        // 2. 获取所有方法
        Method[] methods1 = dogClass.getDeclaredMethods();
        for (Method m: methods1) {
            System.out.println("方法名: " + m.getName());
            System.out.println("返回值类型: " + m.getReturnType());
            System.out.println("修饰符: " + m.getModifiers());

            Class<?>[] parameterTypes = m.getParameterTypes();
            for (Class c: parameterTypes) {
                System.out.println("参数类型: " + c.getName());
            }

            System.out.println("==============================");
        }
    }

    public static void main(String[] args) {
        try {
            testGetMethodByReflect();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
